from rest_framework.views import APIView
from question.serializers.reply_serializers import *
from question.models import *
from rest_framework.response import Response


class ReplyView10(APIView):
    def post(self, request):
            serializer = ReplySerializer(data=request.data)
            serializer.is_valid(raise_exception=True)
            serializer.save(user=request.user)

            return Response({'message': '发布成功',
                             'success': True})
    def get(self,request):
        serializer = ReplySerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save(user=request.user)

        return Response({'message': '发布成功',
                         'success': True})


class ReplyView11(APIView):
    def put(self, request, id):
        cc = Reply.objects.get(id=id)
        count = cc.useful_count + 1
        cc.useful_count = count
        cc.save()
        return Response({'message': 'ok',
                         'success': True})


class ReplyView12(APIView):
    def put(self, request):
        return Response({'message': 'ok',
                         'success': True})
